import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { TilePanel } from "../equipment/TilePanel";
import { KingWarNoteRenderer } from "./KingWarNoteRenderer";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ListEvent } from "../../../../fl/events/ListEvent";
import { ImagesConst } from "../../resource/ImagesConst";
import { GScrollPane } from "../../../../com/mui/controls/GScrollPane";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Cache } from "../../cache/Cache";
import { ClockManager } from "../../manager/ClockManager";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class KingWarNotePanel
    
    export  class KingWarNotePanel extends View
    {
        constructor()
        {
            super();
            this._allDateArr = [];
            this._displayListArr = [];
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createBg(0, 0, 802, 124, this);
            this._btnLeft = ObjCreate.createGLoadedButton(ResFileConst.KingLeftTurnBtn, 2, 53, 20, 20, this);
            this._btnRight = ObjCreate.createGLoadedButton(ResFileConst.KingRightTurnBtn, 779, 53, 20, 20, this);
            this._btnRight.addEventListener(flash.events.MouseEvent.CLICK, this.onRLBtnClick);
            this._btnLeft.addEventListener(flash.events.MouseEvent.CLICK, this.onRLBtnClick);
            this._dateList = new TilePanel();
            this._dateList.columnWidth = 107;
            this._dateList.rowHeight = 112;
            this._dateList.columnCount = 7;
            this._dateList.rowCount = 1;
            this._dateList.horizontalGap = 1;
            this._dateList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._dateList.setStyle("cellRenderer", KingWarNoteRenderer);
            this._dateList.setSize(753, 115);
            this._dateList.move(22, 7);
            this._dateList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._dateList.verticalScrollPolicy = ScrollPolicy.OFF;
            this._dateList.addEventListener(ListEvent.ITEM_CLICK, this.ondateItemClick);
            addChild(this._dateList);
            ObjCreate.createBg(0, 127, 399, 358, this);
            ObjCreate.createBg(3, 126, 395, 27, this, ImagesConst.RbListHeader);
            this._sbmI = ObjCreate.createBitmap("", 132, 134, this);
            ObjCreate.createBg(402, 127, 399, 358, this);
            ObjCreate.createBg(405, 126, 395, 27, this, ImagesConst.RbListHeader);
            this._sbmII = ObjCreate.createBitmap("", 551, 134, this);
            this._txDescRight = ObjCreate.createTextField("", 412, 174, 360, 314, this);
            this._txDescRight.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._txDescRight.multiline = true;
            this._txDescRight.wordWrap = true;
            this._txDescRight.mouseWheelEnabled = false;
            this._txDescLeft = ObjCreate.createTextField("", 10, 174, 360, 314, this);
            this._txDescLeft.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._txDescLeft.multiline = true;
            this._txDescLeft.wordWrap = true;
            this._txDescLeft.mouseWheelEnabled = false;
            this._contentPaneRight = new GScrollPane();
            this._contentPaneRight.styleName = "GScrollPane";
            this._contentPaneRight.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._contentPaneRight.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._contentPaneRight.width = 380;
            this._contentPaneRight.height = 330;
            this._contentPaneRight.x = 406;
            this._contentPaneRight.y = 154;
            this._contentPaneRight.source = this._txDescRight;
            this.addChild(this._contentPaneRight);
            this._contentPaneLeft = new GScrollPane();
            this._contentPaneLeft.styleName = "GScrollPane";
            this._contentPaneLeft.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._contentPaneLeft.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._contentPaneLeft.width = 378;
            this._contentPaneLeft.height = 330;
            this._contentPaneLeft.x = 6;
            this._contentPaneLeft.y = 154;
            this._contentPaneLeft.source = this._txDescLeft;
            this.addChild(this._contentPaneLeft);
            LoaderHelp.addResCallBack(ResFileConst.kingWar, this.onLoadBmResource);
            this.updateInfo();
            this.selecteDefultDate();
            this._displayListArr = this.getCurrentDisplayList();
            this._dateList.dataProvider = new DataProvider(this._displayListArr);
            var loc1=this._displayListArr[0] as Object;
            this._dateList.selectedItem = loc1;
            this.getNote(loc1);
            return;
        }

        /* internal  */setFirClick(): void
        {
            this._dateList.selectedIndex = 0;
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            this._sbmI.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_note1);
            this._sbmII.bitmapData = GlobalClass.getBitmapData(ImagesConst.kingWar_note2);
            return;
        }

        protected ondateItemClick(arg1: ListEvent): void
        {
            var loc1=arg1.item as Object;
            this.getNote(loc1);
            return;
        }

        /* internal  */getNote(arg1: Object): void
        {
            var loc1=null;
            if (arg1 !== null) 
            {
                loc1 = new Date(arg1.year, arg1.month, arg1.day);
                Dispatcher.dispatchEvent(new DataEvent(EventName.KingWarGetNote, loc1));
            }
            return;
        }

        protected onRLBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._btnRight:
                {
                    if (this._startIndex + KingWarNotePanel.MAX_DISPLAY_LENGTH < this._allDateArr.length) 
                    {
                        var loc2=((loc1 = this)._startIndex + 1);
                        loc1._startIndex = loc2;
                        this._displayListArr = this.getCurrentDisplayList();
                        this._dateList.dataProvider = new DataProvider(this._displayListArr);
                        this.getNote(this._dateList.selectedItem);
                    }
                    break;
                }
                case this._btnLeft:
                {
                    if (this._startIndex > 0) 
                    {
                        loc2 = ((loc1 = this)._startIndex - 1);
                        loc1._startIndex = loc2;
                        this._displayListArr = this.getCurrentDisplayList();
                        this._dateList.dataProvider = new DataProvider(this._displayListArr);
                        this.getNote(this._dateList.selectedItem);
                    }
                    break;
                }
            }
            return;
        }

        public updateInfo(): void
        {
            if (Cache.instance.kingwar.sArenaInfo) 
            {
                this._allDateArr = Cache.instance.kingwar.getAllDateArr();
                this._txDescRight.htmlText = "<textFormat leading=\'7\'>" + Cache.instance.kingwar.getRightStrings() + "</textFormat>";
                this._txDescLeft.htmlText = "<textFormat leading=\'7\'>" + Cache.instance.kingwar.getLeftStrings() + "</textFormat>";
                this._contentPaneRight.update();
                this._contentPaneLeft.update();
            }
            return;
        }

        /* internal  */selecteDefultDate(): void
        {
            var loc2=null;
            var loc1=ClockManager.instance.nowDate;
            this._startIndex = 0;
            var loc3=0;
            while (loc3 < this._allDateArr.length) 
            {
                loc2 = this._allDateArr[loc3];
                if (loc1.getFullYear() == loc2.year && loc1.getMonth() == loc2.month && loc1.getDate() == loc2.day) 
                {
                    this._startIndex = loc3;
                    break;
                }
                ++loc3;
            }
            return;
        }

        /* internal  */getCurrentDisplayList(): Array<any>
        {
            var loc3=null;
            var loc1=[];
            var loc2=this._startIndex + KingWarNotePanel.MAX_DISPLAY_LENGTH;
            var loc4=this._startIndex;
            while (loc4 < loc2) 
            {
                loc3 = this._allDateArr[loc4];
                if (loc3) 
                {
                    loc1.push(loc3);
                }
                else 
                {
                    loc1.push(null);
                }
                ++loc4;
            }
            return loc1;
        }

        /* internal */ static /* const */MAX_DISPLAY_LENGTH: int=7;

        /* internal */ /* var */_btnRight: GLoadedButton;

        /* internal */ /* var */_btnLeft: GLoadedButton;

        /* internal */ /* var */_dateList: TilePanel;

        /* internal */ /* var */_allDateArr: Array<any>;

        /* internal */ /* var */_startIndex: int=0;

        /* internal */ /* var */_displayListArr: Array<any>;

        /* internal */ /* var */_sbmI: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sbmII: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_contentPaneRight: GScrollPane;

        /* internal */ /* var */_contentPaneLeft: GScrollPane;

        /* internal */ /* var */_txDescRight: Object /* flash.text.TextField */;

        /* internal */ /* var */_txDescLeft: Object /* flash.text.TextField */;
    }
